import { WeaInput, WeaSelect, WeaBrowser, WeaCheckbox, WeaTextarea, WeaUpload } from 'ecCom';
const util = {
    href: {
        doc: (docId, meetingId) => `/spa/document/index.jsp?id=${docId}&meetingid=${meetingId}`
    },
    getBrowserDatas: (record, key) => {
        let replaceDatas = [];
        if (record[key + 'span'] !== undefined) {
            let keys = record[key].split(',');
            let values = record[key + 'span'].split(',');
            if (keys.length === values.length) {
                keys.map((k, i) => {
                    replaceDatas.push({ id: k, name: values[i] });
                });
            } else {
                console && console.error('浏览按钮数据有误！！显示名中不能包含有英文逗号" , "');
            }
        }
        return replaceDatas;
    },
  
  
    tableCol: {
        render: (col) => {
            const { com = [] } = col;
            return (text, record, index) => {
                let _com = [];
                
                com.map(c => {
                    if (typeof c.props === 'object') {
                        _com.push(c);
                    } else {
                        const { key, label = '', type = 'INPUT', options = [], browserConditionParam = {}, width = 120 } = c;
                        const viewAttr = 1;
                        const _type = type.toUpperCase();
                        let otherParams = c.otherParams&&{...c.otherParams} || {}
                        _com.push(
                            <span >
                                {label && <span style={{ marginLeft: 5 }}>{label}</span>}
                                {(_type === 'INPUT' || _type === 'DATEPICKER' || _type === 'TIMEPICKER') &&
                                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@trrv6h@${key}`}
                                        defaultValue={record[key]}
                                        value={record[key]}
                                        //style={{width, display: 'inline-block'}} 
                                        viewAttr={viewAttr}
                                    />
                                }
                                {_type === 'SELECT' &&
                                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@235tyb@${key}`}
                                        defaultValue={record[key]}
                                        value={record[key]}
                                        options={options}
                                        //style={{width, display: 'inline-block'}}
                                        viewAttr={viewAttr}
                                    />
                                }
                                {_type === 'BROWSER' &&
                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@wged4m@${key}`}
                                        {...browserConditionParam}
                                        replaceDatas={util.getBrowserDatas(record, key)}
                                        //inputStyle={{width, display: 'inline-block'}}
                                        viewAttr={viewAttr}
                                    />
                                }
                                {_type === 'CHECKBOX' &&
                                    <WeaCheckbox ecId={`${this && this.props && this.props.ecId || ''}_WeaCheckbox@0b4nun@${key}`}
                                        // style={{width, display: 'inline-block'}}
                                        value={record[key]}
                                        viewAttr={viewAttr}
                                    />
                                }
                                 
                                {_type === 'TEXTAREA' &&
                                    <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@9dtwy3@${key}`}
                                        defaultValue={record[key]}
                                        value={record[key]}
                                        viewAttr={viewAttr}
                                    />
                                }
                                 {_type === 'FILEDUPLOAD' &&
                                    <WeaUpload ecId={`${this && this.props && this.props.ecId || ''}_WeaUpload@5r90tq@${key}`}
                                        {...otherParams}
                                        datas={record[key].datas}
                                        showLoadInFront={true}//
                                        viewAttr={viewAttr}
                                    />
                                }
                            </span>
                        )
                    }
                });
                return (
                    <div>
                        {_com}
                    </div>
                )
            }
        }
    }
};
export default util;